package www.wen.com.common.lib.base.activity

import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.gyf.immersionbar.ImmersionBar
import www.wen.com.common.lib.util.KeyboardUtils


/**
 * @author WEN
 * @Description:
 * @date 2020/11/1 21:54
 */
abstract class BaseActivity<K : ViewDataBinding> : AppCompatActivity() {

    protected open lateinit var dataBinding: K

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //无标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        //设置竖屏
        super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)

        dataBinding = DataBindingUtil.setContentView(this, getLayout())

        initialize()
        initImmersionBar()
    }

    abstract fun getLayout(): Int

    //初始化沉浸式
    open fun initImmersionBar() {
        ImmersionBar.with(this).init()
    }

    abstract fun initialize()

    override fun finish() {
        //防止activity关闭后键盘没有隐藏
        KeyboardUtils.hideSoftInput(this)
        super.finish()
    }

}